class Solution {
public:
    bool check(vector<int>& quantities,int max,int n)
    {
        int ans=0;
        for(int i=0;i<quantities.size();i++)
        {
            int x=quantities[i];
            ans+=(x-1)/max+1;//处理两个最大值的情况
            if(ans>n)
            {
                return false;
            }
        }
        return true;
    }
    int minimizedMaximum(int n, vector<int>& quantities) {
        sort(quantities.begin(),quantities.end());
        int l=1;
        int r=quantities.back();
        int ans=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(check(quantities,mid,n))
            {
                ans=mid;
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return l;
        
    }
};